'use strict';

/**
 * 数据库专属配置文件
 * 核心：从 environment 读取 MySQL 原始变量，组装 sequelize 所需的完整配置
 */
const config = require('./environment.config');

const databaseConfig = {
    host: config.mysqlHost,
    port: config.mysqlPort,
    username: config.mysqlUser,
    password: config.mysqlPassword,
    database: config.mysqlDatabase,
    charset: config.mysqlCharset,
    dialect: 'mysql', // 告诉sequelize用MySQL方言
    timezon: '+08:00',

    // 额外配置：避免数据失真、适配连接
    dialectOptions: {
        decimalNumbers: true, // 支持Decimal类型（工资、金额等字段不会失真）
        charset: config.mysqlCharset,
    },

    // 复用之前配置的连接池
    pool: {
        max: config.mysqlPoolMax,
        min: config.mysqlPoolMin,
        idle: config.mysqlPoolIdle,
        acquire: config.mysqlPoolAcquire,
        evict: config.mysqlPoolEvict,
    },

    // MySQL日志：开发环境打印SQL，生产环境关闭
    logging: config.nodeEnv === 'development' ? console.log : false,
};

module.exports = databaseConfig;
